package Gui.Dialogs;

import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

import Gui.DiceImagePanel;
import Gui.GameFrame;
import Main.Defines;
import PlayerManager.Chance;

public class ViewLottoCard extends JDialog {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6891649024804010062L;

	// MAGIC NUMBERS
	private void buildUIContents() {
		try {
			ArrayList<Chance> lc = Defines.CP().getLottoCard().getArrayList();
			JPanel row1 = new JPanel();
			JPanel row2 = new JPanel();
			JPanel row3 = new JPanel();
			
			JLabel spacer = new JLabel(" ");
			row1.add(new DiceImagePanel().getDicePanel(false, lc.get(0)
					.getFirst()));
			row1.add(new DiceImagePanel().getDicePanel(true, lc.get(0)
					.getSecond()));
			row1.add(spacer);
			row1.add(new DiceImagePanel().getDicePanel(false, lc.get(1)
					.getFirst()));
			row1.add(new DiceImagePanel().getDicePanel(true, lc.get(1)
					.getSecond()));
			

			row2.add(new DiceImagePanel().getDicePanel(false, lc.get(2)
					.getFirst()));
			row2.add(new DiceImagePanel().getDicePanel(true, lc.get(2)
					.getSecond()));
			row2.add(spacer);
			row2.add(new DiceImagePanel().getDicePanel(false, lc.get(3)
					.getFirst()));
			row2.add(new DiceImagePanel().getDicePanel(true, lc.get(3)
					.getSecond()));


			row3.add(new DiceImagePanel().getDicePanel(false, lc.get(4)
					.getFirst()));
			row3.add(new DiceImagePanel().getDicePanel(true, lc.get(4)
					.getSecond()));
			row3.add(spacer);
			row3.add(new DiceImagePanel().getDicePanel(false, lc.get(5)
					.getFirst()));
			row3.add(new DiceImagePanel().getDicePanel(true, lc.get(5)
					.getSecond()));
			
			add(row1);
			add(row2);
			add(row3);
			
			JButton ok = new JButton("OK");
			ok.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					dispose();
					
				}
			});
			
		}
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public ViewLottoCard() {
		//super(GameFrame.getInstance(), String.format("Player %d's Lotto Card",Defines.CP().getIDPrintable()), true);
		setModalityType(getModalityType().APPLICATION_MODAL);
		setLayout(new GridLayout(0, 1, 0, 10));
		
		buildUIContents();
		
		pack();
		
		if(getTitle() != null){
			FontMetrics fm = getFontMetrics(getFont());
			int width = fm.stringWidth(getTitle()) + Defines.ICON_WIDTH;
			width = (int) Math.max(width*1.2, getPreferredSize().getWidth());
			setSize(new Dimension(width, getHeight()));
		}
		setLocationRelativeTo(GameFrame.getInstance());
		setVisible(true);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	}
}
